<?php
/**
 * Leek - Zend Framework Components
 *
 * @category   Leek
 * @package    Leek_Application
 * @subpackage Resource
 * @author     Chris Jones <leeked@gmail.com>
 * @link       http://code.google.com/p/leek-zf-components/
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version    $Id: Log.php 81 2010-01-07 16:16:13Z leeked $
 */

/**
 * Resource for setting up Zend_Log
 *
 * @category   Leek
 * @package    Leek_Application
 * @subpackage Resource
 * @author     Chris Jones <leeked@gmail.com>
 * @link       http://code.google.com/p/leek-zf-components/
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 */
class Leek_Application_Resource_Log extends Zend_Application_Resource_ResourceAbstract
{
    /**
     * @var array|ArrayObject
     */
    protected $_logs;

    /**
     * Sets the log array.
     * This function only stores the options so we can lazy
     * load the loggers when we need them.
     *
     * @param string $key
     * @param array $options
     * @return Leek_Application_Resource_Log
     */
    public function addLog($key, array $options)
    {
        $options = array_change_key_case($options, CASE_LOWER);

        if (isset($options['writer'])) {

            switch (strtolower($options['writer'])) {

                case 'stream':
                    $this->_logs[$key] = array(
                        'writer' => 'Stream',
                        'path'   => $options['output']
                    );
                    break;

            }

        }

        return $this;
    }

    /**
     * Returns the logs array
     *
     * @return array
     */
    public function getLogs()
    {
        return $this->_logs;
    }

    /**
     * Defined by Zend_Application_Resource_Resource
     *
     * @return void
     */
    public function init()
    {
        $options = $this->getOptions();

        foreach ($options as $key => $logOptions) {
            $this->addLog($key, $logOptions);
        }

        return $this->getLogs();
    }
}
